package com.job.DQH.dqh722.homework01;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Test {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        Random ran = new Random();
        for (int i = 0; i <10 ; i++) {//创建一个10人的学生集合，先按照规则给年龄赋值
            students.add(new Student("student"+i,ran.nextInt(11)+18));
        }
        for (int i = 0; i <10 ; i++) {//重新给10个人的年龄赋值，并制造异常
            int temp;
            try{
                temp = ran.nextInt(21)+10;//把年龄赋值为0~29的随机数
                students.get(i).setAge(temp);//调用setAge，如果temp超出范围，就会抛异常
                System.out.println(students.get(i).getName()+":"+students.get(i).getAge());
            }catch (AgeException e){
                e.printStackTrace();
            }
        }
    }
}
